.class public Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;
.super Lcom/burstly/lib/network/request/AbortableAsyncTask;
.source "TrackDownloadRequest.java"


# annotations
.annotation system Ldalvik/annotation/Signature;
    value = {
        "Lcom/burstly/lib/network/request/AbortableAsyncTask",
        "<",
        "Ljava/lang/String;",
        ">;"
    }
.end annotation


# static fields
.field private static final CONFIRM_DOWNLOAD_URI:Ljava/lang/String; = "/scripts/ConfirmDownload.aspx"

.field private static final LOG:Lcom/burstly/lib/util/LoggerExt;


# instance fields
.field private mCallback:Lcom/burstly/lib/network/request/IRequestCallback;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Lcom/burstly/lib/network/request/IRequestCallback",
            "<",
            "Ljava/lang/String;",
            ">;"
        }
    .end annotation
.end field

.field private final mContext:Ljava/lang/ref/WeakReference;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/lang/ref/WeakReference",
            "<",
            "Landroid/content/Context;",
            ">;"
        }
    .end annotation
.end field

.field private final mDeviceId:Ljava/lang/String;


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 58
    invoke-static {}, Lcom/burstly/lib/util/LoggerExt;->getInstance()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v0

    sput-object v0, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->LOG:Lcom/burstly/lib/util/LoggerExt;

    return-void
.end method

.method public constructor <init>(Ljava/lang/String;Landroid/content/Context;Ljava/lang/String;)V
    .locals 1
    .parameter "burstlyViewId"
    .parameter "context"
    .parameter "deviceId"

    .prologue
    .line 83
    const-string v0, "/scripts/ConfirmDownload.aspx"

    invoke-direct {p0, v0, p1}, Lcom/burstly/lib/network/request/AbortableAsyncTask;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    .line 84
    iput-object p3, p0, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->mDeviceId:Ljava/lang/String;

    .line 85
    new-instance v0, Ljava/lang/ref/WeakReference;

    invoke-direct {v0, p2}, Ljava/lang/ref/WeakReference;-><init>(Ljava/lang/Object;)V

    iput-object v0, p0, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->mContext:Ljava/lang/ref/WeakReference;

    .line 86
    const-string v0, "application/x-www-form-urlencoded"

    invoke-virtual {p0, v0}, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->setContentType(Ljava/lang/String;)V

    .line 87
    return-void
.end method

.method private static createDataToPost(Landroid/content/Context;Ljava/lang/String;)Lorg/apache/http/client/entity/UrlEncodedFormEntity;
    .locals 9
    .parameter "context"
    .parameter "deviceId"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/UnsupportedEncodingException;
        }
    .end annotation

    .prologue
    .line 100
    invoke-static {p1}, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->fixIdentifier(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    .line 101
    .local v0, deviceIdentifier:Ljava/lang/String;
    new-instance v2, Ljava/util/ArrayList;

    invoke-direct {v2}, Ljava/util/ArrayList;-><init>()V

    .line 102
    .local v2, postParameters:Ljava/util/List;,"Ljava/util/List<Lorg/apache/http/NameValuePair;>;"
    new-instance v1, Lcom/burstly/lib/downloadtracker/DownloadTrackingBean;

    invoke-direct {v1}, Lcom/burstly/lib/downloadtracker/DownloadTrackingBean;-><init>()V

    .line 103
    .local v1, dtRequest:Lcom/burstly/lib/downloadtracker/DownloadTrackingBean;
    new-instance v3, Lorg/apache/http/message/BasicNameValuePair;

    const-string v4, "deviceId"

    invoke-direct {v3, v4, v0}, Lorg/apache/http/message/BasicNameValuePair;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-interface {v2, v3}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 104
    new-instance v3, Lorg/apache/http/message/BasicNameValuePair;

    const-string v4, "bundleId"

    invoke-static {p0}, Lcom/burstly/lib/util/Utils;->getAppPackage(Landroid/content/Context;)Ljava/lang/String;

    move-result-object v5

    invoke-direct {v3, v4, v5}, Lorg/apache/http/message/BasicNameValuePair;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-interface {v2, v3}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 105
    invoke-static {p0}, Lcom/burstly/lib/util/Utils;->getAppPackage(Landroid/content/Context;)Ljava/lang/String;

    move-result-object v3

    invoke-virtual {v1, v3}, Lcom/burstly/lib/downloadtracker/DownloadTrackingBean;->setBundleId(Ljava/lang/String;)V

    .line 106
    new-instance v3, Lorg/apache/http/message/BasicNameValuePair;

    const-string v4, "version"

    invoke-virtual {v1}, Lcom/burstly/lib/downloadtracker/DownloadTrackingBean;->getVersion()Ljava/lang/String;

    move-result-object v5

    invoke-direct {v3, v4, v5}, Lorg/apache/http/message/BasicNameValuePair;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-interface {v2, v3}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 107
    new-instance v3, Lorg/apache/http/message/BasicNameValuePair;

    const-string v4, "distribution"

    invoke-virtual {v1}, Lcom/burstly/lib/downloadtracker/DownloadTrackingBean;->getDistribution()Ljava/lang/Boolean;

    move-result-object v5

    invoke-virtual {v5}, Ljava/lang/Boolean;->toString()Ljava/lang/String;

    move-result-object v5

    invoke-direct {v3, v4, v5}, Lorg/apache/http/message/BasicNameValuePair;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-interface {v2, v3}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 108
    new-instance v3, Lorg/apache/http/message/BasicNameValuePair;

    const-string v4, "host"

    invoke-virtual {v1}, Lcom/burstly/lib/downloadtracker/DownloadTrackingBean;->getHost()Ljava/lang/String;

    move-result-object v5

    invoke-direct {v3, v4, v5}, Lorg/apache/http/message/BasicNameValuePair;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-interface {v2, v3}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 109
    new-instance v3, Lorg/apache/http/message/BasicNameValuePair;

    const-string v4, "token"

    invoke-virtual {v1}, Lcom/burstly/lib/downloadtracker/DownloadTrackingBean;->calculateToken()Ljava/lang/String;

    move-result-object v5

    invoke-direct {v3, v4, v5}, Lorg/apache/http/message/BasicNameValuePair;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-interface {v2, v3}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 110
    new-instance v3, Lorg/apache/http/message/BasicNameValuePair;

    const-string v4, "encDevId"

    invoke-static {p0}, Lcom/burstly/lib/util/Utils;->encryptedDeviceId(Landroid/content/Context;)Ljava/lang/String;

    move-result-object v5

    invoke-direct {v3, v4, v5}, Lorg/apache/http/message/BasicNameValuePair;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-interface {v2, v3}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 111
    new-instance v3, Lorg/apache/http/message/BasicNameValuePair;

    const-string v4, "encAndroidId"

    invoke-static {p0}, Lcom/burstly/lib/util/Utils;->encryptedAndroidId(Landroid/content/Context;)Ljava/lang/String;

    move-result-object v5

    invoke-direct {v3, v4, v5}, Lorg/apache/http/message/BasicNameValuePair;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-interface {v2, v3}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 113
    sget-object v3, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v4, "BurstlyRequestTask"

    const-string v5, "Download track data to post is {0}"

    const/4 v6, 0x1

    new-array v6, v6, [Ljava/lang/Object;

    const/4 v7, 0x0

    const-string v8, "UTF-8"

    invoke-static {v2, v8}, Lorg/apache/http/client/utils/URLEncodedUtils;->format(Ljava/util/List;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v8

    aput-object v8, v6, v7

    invoke-virtual {v3, v4, v5, v6}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 114
    new-instance v3, Lorg/apache/http/client/entity/UrlEncodedFormEntity;

    const-string v4, "UTF-8"

    invoke-direct {v3, v2, v4}, Lorg/apache/http/client/entity/UrlEncodedFormEntity;-><init>(Ljava/util/List;Ljava/lang/String;)V

    return-object v3
.end method

.method private static fixIdentifier(Ljava/lang/String;)Ljava/lang/String;
    .locals 3
    .parameter "deviceId"

    .prologue
    .line 124
    move-object v0, p0

    .line 125
    .local v0, deviceIdentifier:Ljava/lang/String;
    invoke-virtual {v0}, Ljava/lang/String;->length()I

    move-result v1

    rem-int/lit8 v1, v1, 0x2

    if-eqz v1, :cond_0

    .line 126
    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v1, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    const-string v2, "0"

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    .line 128
    :cond_0
    return-object v0
.end method


# virtual methods
.method protected bridge synthetic convertServerResponse(Ljava/lang/String;)Ljava/lang/Object;
    .locals 1
    .parameter "x0"

    .prologue
    .line 48
    invoke-virtual {p0, p1}, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->convertServerResponse(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method

.method protected convertServerResponse(Ljava/lang/String;)Ljava/lang/String;
    .locals 1
    .parameter "response"

    .prologue
    .line 133
    iget-object v0, p0, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->mCallback:Lcom/burstly/lib/network/request/IRequestCallback;

    if-eqz v0, :cond_0

    .line 134
    iget-object v0, p0, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->mCallback:Lcom/burstly/lib/network/request/IRequestCallback;

    invoke-interface {v0, p1}, Lcom/burstly/lib/network/request/IRequestCallback;->onSuccessInBackground(Ljava/lang/Object;)V

    .line 136
    :cond_0
    const/4 v0, 0x0

    iput-object v0, p0, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->mCallback:Lcom/burstly/lib/network/request/IRequestCallback;

    .line 137
    return-object p1
.end method

.method public getCallback()Lcom/burstly/lib/network/request/IRequestCallback;
    .locals 1
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "()",
            "Lcom/burstly/lib/network/request/IRequestCallback",
            "<",
            "Ljava/lang/String;",
            ">;"
        }
    .end annotation

    .prologue
    .line 176
    iget-object v0, p0, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->mCallback:Lcom/burstly/lib/network/request/IRequestCallback;

    return-object v0
.end method

.method public setCallback(Lcom/burstly/lib/network/request/IRequestCallback;)V
    .locals 0
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Lcom/burstly/lib/network/request/IRequestCallback",
            "<",
            "Ljava/lang/String;",
            ">;)V"
        }
    .end annotation

    .prologue
    .line 185
    .local p1, callback:Lcom/burstly/lib/network/request/IRequestCallback;,"Lcom/burstly/lib/network/request/IRequestCallback<Ljava/lang/String;>;"
    iput-object p1, p0, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->mCallback:Lcom/burstly/lib/network/request/IRequestCallback;

    .line 186
    return-void
.end method

.method protected tryToConnect(Lorg/apache/http/HttpHost;Lorg/apache/http/client/methods/HttpPost;)Ljava/lang/String;
    .locals 13
    .parameter "host"
    .parameter "post"

    .prologue
    const/4 v6, 0x0

    const/4 v12, 0x0

    .line 142
    iget-object v7, p0, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->mContext:Ljava/lang/ref/WeakReference;

    invoke-virtual {v7}, Ljava/lang/ref/WeakReference;->get()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Landroid/content/Context;

    .line 143
    .local v0, ctxt:Landroid/content/Context;
    if-nez v0, :cond_0

    move-object v3, v6

    .line 167
    :goto_0
    return-object v3

    .line 147
    :cond_0
    :try_start_0
    iget-object v7, p0, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->mDeviceId:Ljava/lang/String;

    invoke-static {v0, v7}, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->createDataToPost(Landroid/content/Context;Ljava/lang/String;)Lorg/apache/http/client/entity/UrlEncodedFormEntity;

    move-result-object v2

    .line 148
    .local v2, formEntity:Lorg/apache/http/client/entity/UrlEncodedFormEntity;
    invoke-virtual {p2, v2}, Lorg/apache/http/client/methods/HttpPost;->setEntity(Lorg/apache/http/HttpEntity;)V

    .line 149
    invoke-static {p1, p2}, Lcom/burstly/lib/util/Utils;->makeRequest(Lorg/apache/http/HttpHost;Lorg/apache/http/client/methods/HttpRequestBase;)Lorg/apache/http/HttpResponse;

    move-result-object v4

    .line 150
    .local v4, response:Lorg/apache/http/HttpResponse;
    invoke-interface {v4}, Lorg/apache/http/HttpResponse;->getStatusLine()Lorg/apache/http/StatusLine;

    move-result-object v7

    invoke-interface {v7}, Lorg/apache/http/StatusLine;->getStatusCode()I

    move-result v5

    .line 151
    .local v5, statusCode:I
    const/16 v7, 0xc8

    if-eq v5, v7, :cond_1

    .line 152
    new-instance v7, Ljava/io/IOException;

    new-instance v8, Ljava/lang/StringBuilder;

    invoke-direct {v8}, Ljava/lang/StringBuilder;-><init>()V

    const-string v9, "Status code is "

    invoke-virtual {v8, v9}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v8

    invoke-virtual {v8, v5}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v8

    const-string v9, ", url: "

    invoke-virtual {v8, v9}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v8

    invoke-virtual {v8, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v8

    invoke-virtual {v8}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v8

    invoke-direct {v7, v8}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V

    throw v7
    :try_end_0
    .catch Lorg/apache/http/client/ClientProtocolException; {:try_start_0 .. :try_end_0} :catch_0
    .catch Ljava/io/UnsupportedEncodingException; {:try_start_0 .. :try_end_0} :catch_1
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_2

    .line 158
    .end local v2           #formEntity:Lorg/apache/http/client/entity/UrlEncodedFormEntity;
    .end local v4           #response:Lorg/apache/http/HttpResponse;
    .end local v5           #statusCode:I
    :catch_0
    move-exception v1

    .line 159
    .local v1, e:Lorg/apache/http/client/ClientProtocolException;
    sget-object v7, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v8, "BurstlyRequestTask"

    invoke-virtual {v1}, Lorg/apache/http/client/ClientProtocolException;->getMessage()Ljava/lang/String;

    move-result-object v9

    new-array v10, v12, [Ljava/lang/Object;

    invoke-virtual {v7, v8, v9, v10}, Lcom/burstly/lib/util/LoggerExt;->logError(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .end local v1           #e:Lorg/apache/http/client/ClientProtocolException;
    :goto_1
    move-object v3, v6

    .line 167
    goto :goto_0

    .line 154
    .restart local v2       #formEntity:Lorg/apache/http/client/entity/UrlEncodedFormEntity;
    .restart local v4       #response:Lorg/apache/http/HttpResponse;
    .restart local v5       #statusCode:I
    :cond_1
    :try_start_1
    invoke-interface {v4}, Lorg/apache/http/HttpResponse;->getEntity()Lorg/apache/http/HttpEntity;

    move-result-object v7

    const-string v8, "UTF-8"

    invoke-static {v7, v8}, Lorg/apache/http/util/EntityUtils;->toString(Lorg/apache/http/HttpEntity;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v3

    .line 155
    .local v3, outputString:Ljava/lang/String;
    sget-object v7, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v8, "BurstlyRequestTask"

    const-string v9, "Download track result is {0}"

    const/4 v10, 0x1

    new-array v10, v10, [Ljava/lang/Object;

    const/4 v11, 0x0

    aput-object v3, v10, v11

    invoke-virtual {v7, v8, v9, v10}, Lcom/burstly/lib/util/LoggerExt;->logInfo(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
    :try_end_1
    .catch Lorg/apache/http/client/ClientProtocolException; {:try_start_1 .. :try_end_1} :catch_0
    .catch Ljava/io/UnsupportedEncodingException; {:try_start_1 .. :try_end_1} :catch_1
    .catch Ljava/io/IOException; {:try_start_1 .. :try_end_1} :catch_2

    goto :goto_0

    .line 161
    .end local v2           #formEntity:Lorg/apache/http/client/entity/UrlEncodedFormEntity;
    .end local v3           #outputString:Ljava/lang/String;
    .end local v4           #response:Lorg/apache/http/HttpResponse;
    .end local v5           #statusCode:I
    :catch_1
    move-exception v1

    .line 162
    .local v1, e:Ljava/io/UnsupportedEncodingException;
    sget-object v7, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v8, "BurstlyRequestTask"

    invoke-virtual {v1}, Ljava/io/UnsupportedEncodingException;->getMessage()Ljava/lang/String;

    move-result-object v9

    new-array v10, v12, [Ljava/lang/Object;

    invoke-virtual {v7, v8, v9, v10}, Lcom/burstly/lib/util/LoggerExt;->logError(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    goto :goto_1

    .line 164
    .end local v1           #e:Ljava/io/UnsupportedEncodingException;
    :catch_2
    move-exception v1

    .line 165
    .local v1, e:Ljava/io/IOException;
    sget-object v7, Lcom/burstly/lib/downloadtracker/TrackDownloadRequest;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v8, "BurstlyRequestTask"

    invoke-virtual {v1}, Ljava/io/IOException;->getMessage()Ljava/lang/String;

    move-result-object v9

    new-array v10, v12, [Ljava/lang/Object;

    invoke-virtual {v7, v8, v9, v10}, Lcom/burstly/lib/util/LoggerExt;->logError(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    goto :goto_1
.end method
